//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "ProbabilityOfNEvents.h"
using namespace Cephei::QL::Experimental::Credit;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Experimental::Credit::CProbabilityOfNEvents::CProbabilityOfNEvents (Int32 n) 
{
	_pSpinlock = new boost::detail::spinlock ();
    try
    {
#ifdef HANDLE
        _phProbabilityOfNEvents = NULL;
#endif
        int _n = (int)ValueHelper::Convert (n);
        _ppProbabilityOfNEvents = new boost::shared_ptr<QuantLib::ProbabilityOfNEvents> (new QuantLib::ProbabilityOfNEvents ( _n ));
        
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Experimental::Credit::CProbabilityOfNEvents::CProbabilityOfNEvents (boost::shared_ptr<QuantLib::ProbabilityOfNEvents>& childNative, Object^ owner) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phProbabilityOfNEvents = NULL;
#endif
	_ppProbabilityOfNEvents = &childNative;
    
}
Cephei::QL::Experimental::Credit::CProbabilityOfNEvents::CProbabilityOfNEvents (QuantLib::ProbabilityOfNEvents& childNative, Object^ owner) 
{
#ifdef HANDLE
	_phProbabilityOfNEvents = NULL;
#endif
	_ppProbabilityOfNEvents = new boost::shared_ptr<QuantLib::ProbabilityOfNEvents> (&childNative);
    
    _ProbabilityOfNEventsOwner = owner;
    
}

Cephei::QL::Experimental::Credit::CProbabilityOfNEvents::CProbabilityOfNEvents (CProbabilityOfNEvents^ copy) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phProbabilityOfNEvents = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppProbabilityOfNEvents = new boost::shared_ptr<QuantLib::ProbabilityOfNEvents> (copy->GetShared());
        
    }
}
Cephei::QL::Experimental::Credit::CProbabilityOfNEvents::CProbabilityOfNEvents (System::Type^ t) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phProbabilityOfNEvents = NULL;
#endif
	if (!t->IsSubclassOf(CProbabilityOfNEvents::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Experimental::Credit::CProbabilityOfNEvents::CProbabilityOfNEvents (QuantLib::Handle<QuantLib::ProbabilityOfNEvents>& childNative, Object^ owner)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phProbabilityOfNEvents = &childNative;
	_ppProbabilityOfNEvents = &static_cast<boost::shared_ptr<QuantLib::ProbabilityOfNEvents>>(childNative.currentLink());
    
    _ProbabilityOfNEventsOwner = owner;
}
Cephei::QL::Experimental::Credit::CProbabilityOfNEvents::CProbabilityOfNEvents (QuantLib::Handle<QuantLib::ProbabilityOfNEvents> childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phProbabilityOfNEvents = &childNative;
	_ppProbabilityOfNEvents = &static_cast<boost::shared_ptr<QuantLib::ProbabilityOfNEvents>>(childNative.currentLink());
    
}
#endif
#ifdef STRUCT
Cephei::QL::Experimental::Credit::CProbabilityOfNEvents::CProbabilityOfNEvents (QuantLib::ProbabilityOfNEvents childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phProbabilityOfNEvents = NULL;
#endif
	_ppProbabilityOfNEvents = new boost::shared_ptr<QuantLib::ProbabilityOfNEvents> (new QuantLib::ProbabilityOfNEvents (childNative));
    
}
#endif

Cephei::QL::Experimental::Credit::CProbabilityOfNEvents::~CProbabilityOfNEvents ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
        _pSpinlock = NULL;
    }
    if (_ppProbabilityOfNEvents != NULL)
    {
	    delete _ppProbabilityOfNEvents;
        _ppProbabilityOfNEvents = NULL;
    }
}
Cephei::QL::Experimental::Credit::CProbabilityOfNEvents::!CProbabilityOfNEvents ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
    }
    if (_ppProbabilityOfNEvents != NULL)
    {
	    delete _ppProbabilityOfNEvents;
    }
}
QuantLib::ProbabilityOfNEvents& Cephei::QL::Experimental::Credit::CProbabilityOfNEvents::GetReference ()
{
    if (_ppProbabilityOfNEvents == NULL) throw gcnew NativeNullException ();
	return **_ppProbabilityOfNEvents;
}
boost::shared_ptr<QuantLib::ProbabilityOfNEvents>& Cephei::QL::Experimental::Credit::CProbabilityOfNEvents::GetShared ()
{
    if (_ppProbabilityOfNEvents == NULL) throw gcnew NativeNullException ();
	return *_ppProbabilityOfNEvents;
}
QuantLib::ProbabilityOfNEvents* Cephei::QL::Experimental::Credit::CProbabilityOfNEvents::GetPointer ()
{
    if (_ppProbabilityOfNEvents == NULL) throw gcnew NativeNullException ();
	return &**_ppProbabilityOfNEvents;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::ProbabilityOfNEvents>& Cephei::QL::Experimental::Credit::CProbabilityOfNEvents::GetHandle ()
{
	if (_phProbabilityOfNEvents == NULL)
	{
		_phProbabilityOfNEvents = new Handle<QuantLib::ProbabilityOfNEvents> (*_ppProbabilityOfNEvents);
	}
	return *_phProbabilityOfNEvents;
}
#endif
bool Cephei::QL::Experimental::Credit::CProbabilityOfNEvents::HasNative () 
{
	return (_ppProbabilityOfNEvents != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Experimental::Credit::IProbabilityOfNEvents^ Cephei::QL::Experimental::Credit::CProbabilityOfNEvents_Factory::Create (Int32 n)
{
    return gcnew CProbabilityOfNEvents ( n);
}
